
<?php
$id = $_POST['id']; If ($id == "_empty" || $_POST['oper'] =='new') $new = 1;  //echo $id;
if ($_POST['day_of_week']) $fields .= "day_of_week='" . $_POST['day_of_week']."', "; 
if ($_POST['start_time']) $fields .= "start_time='" . $_POST['start_time']."', "; 
if ($_POST['end_time']) $fields .= "end_time='" . $_POST['end_time']."', ";
if ($_GET['show_id']) $fields .= "show_id='" . $_GET['show_id']."', ";



$fields = rtrim($fields, ', ');

// connect to the database
include "../../includes/functions.php";

echo db_connect(); 
 
 if ($_POST['oper'] =='del') {
	$result = mysql_query('DELETE FROM show_occurrances WHERE `id` = "'.$id.'"');
	if (!$result) { echo "error deleting record on server side.";}
	exit;	
}
 
 
if ($new) {
	$SQL = "INSERT INTO show_occurrances (id, show_id, day_of_week, start_time, end_time) VALUES ('','".$_GET['show_id']."','".$_POST['day_of_week']."','".$_POST['start_time']."','".$_POST['end_time']."')"; //echo $SQL;
} else {
	$SQL = "UPDATE show_occurrances SET $fields WHERE id = '$id'"; //echo $SQL;
}

$result = mysql_query( $SQL ) or die("Couldnt execute query.".mysql_error());


?>	
